﻿using System;
using YAXLib;
using System.Globalization;

namespace RaytracerLib.Resamplers.Filters
{
    public class BicubicFilter : Filter
    {
        [YAXNode]
        public double A = -0.5;

        public BicubicFilter()
            : base(2)
        { 
        }

        public override string Name
        {
            get
            {
                return "Bicubic";
            }
        }

        public override FilterType FilterType 
        {
            get
            {
                return FilterType.Bicubic;
            }
        }

        public override double Evaluate(double a_value)
        {
            double v = Math.Abs(a_value);

            if (v > 2)
                return 0;

            double v2 = v * v;
            if (v > 1)
                return A * v2 * v - 5 * A * v2 + 8 * A * v - 4 * A;
            else
                return v2 * ((A + 2) * v - (A + 3)) + 1;
        }

        public override string ToString()
        {
            return String.Format(CultureInfo.InvariantCulture, "Bicubic, A: {0}", A);
        }
    }
}